; ***************************************************************************
;   Group: Fantastic Five
;   Date: 4/23/08
;   Description: This program computes the factorial of a user inputted value
; ***************************************************************************
;
BEG             ; Begin program
;
GET     R0      ; Get initial value
PTC     '\n'    ; Print new line
;
JLT     R0,31   ; Check if number is less than zero
MOV     R4,1    ; Move 1 into R4
JZ      R0,28   ; Check if user inputted 0, print 1 if so
CMP     R0,R4   ; Check if user inputted 1
JZ      RC,28   ; Print 1 if so
;
CPY     R0,R1   ; Copy initial value into R1
DEC     R1      ; Start counter
;
MUL     R0,R1   ; Multiply next value and running factorial
DEC     R1      ; Decrement counter
JNZ     R1,21   ; Jump back to factorial loop if counter not zero yet
;
PUT     R0      ; Output result
JMP     39      ; Jump to end
;
PUT     R4      ; Output 1
JMP     39      ; Jump to end
;
PTC     'I'     ; Print error message
PTC     'N'     ;
PTC     'V'     ;
PTC     'A'     ;
PTC     'L'     ;
PTC     'I'     ;
PTC     'D'     ; End of error message
;
PTC     '\n'    ; Print new line
END             ; End of program
